package model;

import java.util.Iterator;
import java.util.SortedSet;
import java.util.TreeSet;

public class MockRoomRepo implements RoomRepo {
  SortedSet<Room> rooms = new TreeSet<Room>();
  // singleton
  private static final MockRoomRepo mock = new MockRoomRepo();

  public static MockRoomRepo getInstance() {
    return mock;
  }

  private MockRoomRepo() {
    super();
    this.rooms.add(new Room("Room1", new Question("Heads or tails?", "Heads",
        "Tails"), 100, 50));
    this.rooms.add(new Room("Room2", new Question("A or B?", "A", "B"), 10, 5));

    Room r3 = new Room("Room3", new Question("Dollar or Euro?", "Dollar",
        "Euro"), 5, 10);
    UserRepo users = MockUserRepo.getInstance();
    r3.addUser(users.getUserByName("Lucila"));
    r3.addUser(users.getUserByName("Conrado"));
    r3.addUser(users.getUserByName("Andres"));

    this.rooms.add(r3);

  }

  @Override
  public SortedSet<Room> getRooms() {
    return rooms;
  }

  @Override
  public Room getRoom(String name) {
    Iterator<Room> i = this.rooms.iterator();
    Room answer;
    while (i.hasNext()) {
      answer = i.next();
      if (answer.getName().equals(name)) {
        return answer;
      }
    }
    throw new RuntimeException("Room does not exist");
  }
}
